﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;

namespace ZXW.DotNet.Common.DbUtilities
{
    /// <summary>
    /// 有关数据库连接的方法。
    /// </summary>
    public abstract class BaseDbHelper : IDbHelper
    {
        protected DbProviderFactory DbProviderFactory;
        protected string FileName = "BaseDbHelper.txt"; // sql查询句日志
        protected string Name;

        private DbCommand _dbCommand;
        private DbConnection _dbConnection;

        private DbDataAdapter _dbDataAdapter;
        private DbTransaction _dbTransaction;
        protected string connectionString = string.Empty;

        #region public IDbConnection Open()

        /// <summary>
        /// 这时主要的获取数据库连接的方法
        /// </summary>
        /// <returns>数据库连接</returns>
        public IDbConnection Open()
        {
            Open(ConnectionString);
            return _dbConnection;
        }

        #endregion

        #region public IDbConnection Open(string connectionString)

        /// <summary>
        /// 获得新的数据库连接
        /// </summary>
        /// <returns>数据库连接</returns>
        public IDbConnection Open(string connstr)
        {
            // 若是空的话才打开
            if (_dbConnection == null)
            {
                ConnectionString = connstr;
                _dbConnection = DbProviderFactory.CreateConnection();
                if (_dbConnection != null)
                {
                    _dbConnection.ConnectionString = ConnectionString;
                    _dbConnection.Open();
                }
            }
            return _dbConnection;
        }

        #endregion

        #region public IDbConnection GetDbConnection() 获取数据库连接

        /// <summary>
        /// 获取数据库连接
        /// </summary>
        /// <returns>数据库连接</returns>
        public IDbConnection GetDbConnection()
        {
            return _dbConnection;
        }

        #endregion

        #region public IDbTransaction GetDbTransaction() 获取数据源上执行的事务

        /// <summary>
        /// 获取数据源上执行的事务
        /// </summary>
        /// <returns>数据源上执行的事务</returns>
        public IDbTransaction GetDbTransaction()
        {
            return _dbTransaction;
        }

        #endregion

        #region public IDbCommand GetDbCommand() 获取数据源上命令

        /// <summary>
        /// 获取数据源上命令
        /// </summary>
        /// <returns>数据源上命令</returns>
        public IDbCommand GetDbCommand()
        {
            return DbConnection.CreateCommand();
        }

        #endregion

        #region public IDataReader ExecuteReader(string commandText)

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <returns>结果集流</returns>
        public IDataReader ExecuteReader(string commandText)
        {
            _dbCommand = DbConnection.CreateCommand();
            _dbCommand.CommandType = CommandType.Text;
            _dbCommand.CommandText = commandText;
            if (InTransaction)
            {
                _dbCommand.Transaction = _dbTransaction;
            }

            DbDataReader dbDataReader = _dbCommand.ExecuteReader(CommandBehavior.CloseConnection);
            // 写入日志
            WriteLog(commandText);
            return dbDataReader;
        }

        #endregion

        #region public IDataReader ExecuteReader(string commandText, DbParameter[] dbParameters);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>结果集流</returns>
        public IDataReader ExecuteReader(string commandText, DbParameter[] dbParameters)
        {
            return ExecuteReader(CommandType.Text, commandText, dbParameters);
        }

        #endregion

        #region public IDataReader ExecuteReader(string commandText, List<DbParameter> dbParameters);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>结果集流</returns>
        public IDataReader ExecuteReader(string commandText, List<DbParameter> dbParameters)
        {
            return ExecuteReader(CommandType.Text, commandText, dbParameters.ToArray());
        }

        #endregion

        #region public IDataReader ExecuteReader(CommandType commandType, string commandText, DbParameter[] dbParameters)

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>结果集流</returns>
        public IDataReader ExecuteReader(CommandType commandType, string commandText, DbParameter[] dbParameters)
        {
            _dbCommand = DbConnection.CreateCommand();
            _dbCommand.CommandText = commandText;
            _dbCommand.CommandType = commandType;
            if (_dbTransaction != null)
            {
                _dbCommand.Transaction = _dbTransaction;
            }

            if (dbParameters != null)
            {
                _dbCommand.Parameters.Clear();
                foreach (DbParameter dbParameter in dbParameters)
                {
                    if (dbParameter != null)
                    {
                        _dbCommand.Parameters.Add(dbParameter);
                    }
                }
            }

            DbDataReader dbDataReader = _dbCommand.ExecuteReader(CommandBehavior.CloseConnection);
            _dbCommand.Parameters.Clear();
            // 写入日志
            WriteLog(commandText);

            return dbDataReader;
        }

        #endregion

        #region public IDataReader ExecuteReader(CommandType commandType, string commandText, DbParameter[] dbParameters)

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>结果集流</returns>
        public IDataReader ExecuteReader(CommandType commandType, string commandText, List<DbParameter> dbParameters)
        {
            return ExecuteReader(commandType, commandText, dbParameters.ToArray());
        }

        #endregion

        #region public int ExecuteNonQuery(string commandText)

        /// <summary>
        /// 执行查询, SQL BUILDER 用了这个东西？参数需要保存, 不能丢失.
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(string commandText)
        {
            _dbCommand = DbConnection.CreateCommand();
            _dbCommand.CommandType = CommandType.Text;
            _dbCommand.CommandText = commandText;
            if (InTransaction)
            {
                _dbCommand.Transaction = _dbTransaction;
            }
            int returnValue = _dbCommand.ExecuteNonQuery();
            // 写入日志
            WriteLog(commandText);
            return returnValue;
        }

        #endregion

        #region public DbDataAdapter DbDataAdapter 数据库适配器

        /// <summary>
        /// 数据库适配器
        /// </summary>
        public DbDataAdapter DbDataAdapter
        {
            get { return _dbDataAdapter; }

            set { _dbDataAdapter = value; }
        }

        #endregion

        #region public string ConnectionString 数据库连接

        /// <summary>
        /// 数据库连接
        /// </summary>
        public string ConnectionString
        {
            get { return connectionString; }

            set { connectionString = value; }
        }

        #endregion

        #region public bool InTransaction 是否已采用事务

        /// <summary>
        /// 是否已采用事务
        /// </summary>
        public bool InTransaction { get; set; }

        #endregion

        #region public DbConnection DbConnection 数据库适配器

        /// <summary>
        /// 数据库连接
        /// </summary>
        public DbConnection DbConnection
        {
            get { return _dbConnection; }

            set { _dbConnection = value; }
        }

        #endregion

        protected BaseDbHelper(string name)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[name];
            DbProviderFactory = DbProviderFactories.GetFactory(setting.ProviderName);
            connectionString = setting.ConnectionString;
            Name = name;
        }

        // 是否已在事务之中

        #region IDbHelper Members

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(string commandText, DbParameter[] dbParameters)
        {
            return ExecuteNonQuery(CommandType.Text, commandText, dbParameters);
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(string commandText, List<DbParameter> dbParameters)
        {
            return ExecuteNonQuery(CommandType.Text, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(CommandType commandType, string commandText, DbParameter[] dbParameters)
        {
            return ExecuteNonQuery(_dbTransaction, commandType, commandText, dbParameters);
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(CommandType commandType, string commandText, List<DbParameter> dbParameters)
        {
            return ExecuteNonQuery(_dbTransaction, commandType, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="transaction">数据库事务</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(IDbTransaction transaction, CommandType commandType, string commandText,
                                   DbParameter[] dbParameters)
        {
            _dbCommand = DbConnection.CreateCommand();
            _dbCommand.CommandText = commandText;
            _dbCommand.CommandType = commandType;
            if (_dbTransaction != null)
            {
                _dbCommand.Transaction = _dbTransaction;
            }
            if (dbParameters != null)
            {
                _dbCommand.Parameters.Clear();
                foreach (DbParameter dbParameter in dbParameters)
                {
                    if (dbParameter != null)
                    {
                        _dbCommand.Parameters.Add(dbParameter);
                    }
                }
            }
            int returnValue = _dbCommand.ExecuteNonQuery();
            _dbCommand.Parameters.Clear();
            // 写入日志
            WriteLog(commandText);

            return returnValue;
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="transaction">数据库事务</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteNonQuery(IDbTransaction transaction, CommandType commandType, string commandText,
                                   List<DbParameter> dbParameters)
        {
            return ExecuteNonQuery(transaction, commandType, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <returns>object</returns>
        public object ExecuteScalar(string commandText)
        {
            return ExecuteScalar(CommandType.Text, commandText, new DbParameter[0]);
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(string commandText, DbParameter[] dbParameters)
        {
            return ExecuteScalar(CommandType.Text, commandText, dbParameters);
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(string commandText, List<DbParameter> dbParameters)
        {
            return ExecuteScalar(CommandType.Text, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(CommandType commandType, string commandText, DbParameter[] dbParameters)
        {
            return ExecuteScalar(_dbTransaction, commandType, commandText, dbParameters);
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(CommandType commandType, string commandText, List<DbParameter> dbParameters)
        {
            return ExecuteScalar(_dbTransaction, commandType, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="transaction">数据库事务</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(IDbTransaction transaction, CommandType commandType, string commandText,
                                    DbParameter[] dbParameters)
        {
            _dbCommand = DbConnection.CreateCommand();
            _dbCommand.CommandText = commandText;
            _dbCommand.CommandType = commandType;
            if (_dbTransaction != null)
            {
                _dbCommand.Transaction = _dbTransaction;
            }
            if (dbParameters != null)
            {
                _dbCommand.Parameters.Clear();
                foreach (DbParameter dbParameter in dbParameters)
                {
                    if (dbParameter != null)
                    {
                        _dbCommand.Parameters.Add(dbParameter);
                    }
                }
            }
            object returnValue = _dbCommand.ExecuteScalar();
            _dbCommand.Parameters.Clear();
            // 写入日志
            WriteLog(commandText);
            return returnValue;
        }

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="transaction">数据库事务</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>Object</returns>
        public object ExecuteScalar(IDbTransaction transaction, CommandType commandType, string commandText,
                                    List<DbParameter> dbParameters)
        {
            return ExecuteScalar(transaction, commandType, commandText, dbParameters.ToArray());
        }


        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandText">查询</param>
        /// <returns>数据表</returns>
        public DataTable Fill(string commandText)
        {
            var dataTable = new DataTable();
            return Fill(dataTable, CommandType.Text, commandText, new DbParameter[0]);
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="dataTable">目标数据表</param>
        /// <param name="commandText">查询</param>
        /// <returns>数据表</returns>
        public DataTable Fill(DataTable dataTable, string commandText)
        {
            return Fill(dataTable, CommandType.Text, commandText, new DbParameter[0]);
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(string commandText, DbParameter[] dbParameters)
        {
            var dataTable = new DataTable();
            return Fill(dataTable, CommandType.Text, commandText, dbParameters);
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(string commandText, List<DbParameter> dbParameters)
        {
            return Fill(commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="dataTable">目标数据表</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(DataTable dataTable, string commandText, DbParameter[] dbParameters)
        {
            return Fill(dataTable, CommandType.Text, commandText, dbParameters);
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="dataTable">目标数据表</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(DataTable dataTable, string commandText, List<DbParameter> dbParameters)
        {
            return Fill(dataTable, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(CommandType commandType, string commandText, DbParameter[] dbParameters)
        {
            var dataTable = new DataTable();
            return Fill(dataTable, commandType, commandText, dbParameters);
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(CommandType commandType, string commandText, List<DbParameter> dbParameters)
        {
            return Fill(commandType, commandText, dbParameters.ToArray());
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="dataTable">目标数据表</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(DataTable dataTable, CommandType commandType, string commandText,
                              DbParameter[] dbParameters)
        {
            using (_dbCommand = DbConnection.CreateCommand())
            {
                _dbCommand.CommandText = commandText;
                _dbCommand.CommandType = commandType;
                if ((dbParameters != null) && (dbParameters.Length > 0))
                {
                    _dbCommand.Parameters.AddRange(dbParameters);
                }

                _dbDataAdapter = DbProviderFactory.CreateDataAdapter();
                if (_dbDataAdapter != null)
                {
                    _dbDataAdapter.SelectCommand = _dbCommand;
                    _dbDataAdapter.Fill(dataTable);
                    _dbDataAdapter.SelectCommand.Parameters.Clear();
                }
            }
            // 写入日志
            WriteLog(commandText);
            return dataTable;
        }

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="dataTable">目标数据表</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据表</returns>
        public DataTable Fill(DataTable dataTable, CommandType commandType, string commandText,
                              List<DbParameter> dbParameters)
        {
            return Fill(dataTable, commandType, commandText, dbParameters.ToArray());
        }

        #endregion

        #region public DataSet Fill(DataSet dataSet, string commandText, string tableName)

        /// <summary>
        /// 填充数据集
        /// </summary>
        /// <param name="dataSet">目标数据集</param>
        /// <param name="commandText">查询</param>
        /// <param name="tableName">填充表</param>
        /// <returns>数据集</returns>
        public DataSet Fill(DataSet dataSet, string commandText, string tableName)
        {
            return Fill(dataSet, CommandType.Text, commandText, tableName, null);
        }

        #endregion

        #region public DataSet Fill(DataSet dataSet, string commandText, string tableName, DbParameter[] dbParameters)

        /// <summary>
        /// 填充数据集
        /// </summary>
        /// <param name="dataSet">数据集</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="tableName">填充表</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据集</returns>
        public DataSet Fill(DataSet dataSet, string commandText, string tableName, DbParameter[] dbParameters)
        {
            return Fill(dataSet, CommandType.Text, commandText, tableName, dbParameters);
        }

        #endregion

        #region public DataSet Fill(DataSet dataSet, CommandType commandType, string commandText, string tableName, DbParameter[] dbParameters)

        /// <summary>
        /// 填充数据集
        /// </summary>
        /// <param name="dataSet">数据集</param>
        /// <param name="commandType">命令分类</param>
        /// <param name="commandText">sql查询</param>
        /// <param name="tableName">填充表</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据集</returns>
        public DataSet Fill(DataSet dataSet, CommandType commandType, string commandText, string tableName,
                            DbParameter[] dbParameters)
        {
            using (_dbCommand = DbConnection.CreateCommand())
            {
                _dbCommand.CommandText = commandText;
                _dbCommand.CommandType = commandType;
                if ((dbParameters != null) && (dbParameters.Length > 0))
                {
                    _dbCommand.Parameters.AddRange(dbParameters);
                }

                _dbDataAdapter = DbProviderFactory.CreateDataAdapter();
                if (_dbDataAdapter != null)
                {
                    _dbDataAdapter.SelectCommand = _dbCommand;
                    _dbDataAdapter.Fill(dataSet, tableName);
                    _dbDataAdapter.SelectCommand.Parameters.Clear();
                }
            }
            // 写入日志
            WriteLog(commandText);
            return dataSet;
        }

        #endregion

        #region public int ExecuteProcedure(string procedureName)

        /// <summary>
        /// 执行数据库查询
        /// </summary>
        /// <param name="procedureName">存储过程</param>
        /// <returns>int</returns>
        public int ExecuteProcedure(string procedureName)
        {
            return ExecuteNonQuery(CommandType.StoredProcedure, procedureName, new DbParameter[0]);
        }

        #endregion

        #region public int ExecuteProcedure(string procedureName, DbParameter[] dbParameters)

        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="procedureName">存储过程名</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>影响行数</returns>
        public int ExecuteProcedure(string procedureName, DbParameter[] dbParameters)
        {
            return ExecuteNonQuery(CommandType.StoredProcedure, procedureName, dbParameters);
        }

        #endregion

        #region public DataTable ExecuteProcedureForDataTable(string procedureName, string tableName, DbParameter[] dbParameters)

        /// <summary>
        /// 执行数据库脚本
        /// </summary>
        /// <param name="procedureName">存储过程</param>
        /// <param name="tableName">填充表</param>
        /// <param name="dbParameters">参数集</param>
        /// <returns>数据集</returns>
        public DataTable ExecuteProcedureForDataTable(string procedureName, string tableName, DbParameter[] dbParameters)
        {
            var dataTable = new DataTable(tableName);
            Fill(dataTable, CommandType.StoredProcedure, procedureName, dbParameters);
            return dataTable;
        }

        #endregion

        #region public IDbTransaction BeginTransaction()

        /// <summary>
        /// 事务开始
        /// </summary>
        /// <returns>事务</returns>
        public IDbTransaction BeginTransaction()
        {
            if (!InTransaction)
            {
                InTransaction = true;
                _dbTransaction = DbConnection.BeginTransaction();
            }
            return _dbTransaction;
        }

        #endregion

        #region public void CommitTransaction()

        /// <summary>
        /// 递交事务
        /// </summary>
        public void CommitTransaction()
        {
            if (InTransaction)
            {
                // 事务已经完成了，一定要更新标志信息
                InTransaction = false;
                _dbTransaction.Commit();
            }
        }

        #endregion

        #region public void RollbackTransaction()

        /// <summary>
        /// 回滚事务
        /// </summary>
        public void RollbackTransaction()
        {
            if (InTransaction)
            {
                InTransaction = false;
                _dbTransaction.Rollback();
            }
        }

        #endregion

        #region public void Close()

        /// <summary>
        /// 关闭数据库连接
        /// </summary>
        public void Close()
        {
            if (_dbConnection != null)
            {
                _dbConnection.Close();
                _dbConnection.Dispose();
            }
            _dbConnection = null;
            _dbCommand = null;
            _dbDataAdapter = null;
            _dbTransaction = null;
        }

        #endregion

        #region public void WriteLog(string commandText) 写入sql查询句日志

        /// <summary>
        /// 写入sql查询日志
        /// </summary>
        /// <param name="commandText">sql查询</param>
        public void WriteLog(string commandText)
        {
            //此处可以写入日志
            //System.Console.WriteLine(commandText);
        }

        #endregion

        #region IDbHelper 成员

        public abstract DbProviderFactory Instance();

        public abstract string GetDBNow();

        public abstract string GetDBDateTime();

        public abstract string SqlSafe(string value);

        public abstract string PlusSign(params string[] values);

        public abstract string GetParameter(string parameter);

        public abstract DbParameter MakeInParam(string targetFiled, object targetValue);

        public abstract DbParameter[] MakeParameters(string targetFiled, object targetValue);

        public abstract DbParameter[] MakeParameters(string[] targetFileds, object[] targetValues);

        public abstract DbParameter MakeParam(string paramName, DbType dbType, int size, ParameterDirection direction,
                                              object value);

        #endregion
    }
}